package com.chenbei.controller.admin.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenbei.common.domain.vo.ApiResponse;
import com.chenbei.common.domain.vo.Pagination;
import com.chenbei.common.util.ApiResponseUtil;
import com.chenbei.system.domain.SysLoginLog;
import com.chenbei.system.domain.SysOperationLog;
import com.chenbei.system.service.ISysLoginLogService;
import com.chenbei.system.service.ISysOperationLogService;
import com.chenbei.system.vo.req.SysLoginLogReq;
import com.chenbei.system.vo.req.SysOperationLogReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "日志管理")
@RestController
@RequestMapping("/admin/system/log")
public class LogController {

    @Autowired
    private ISysLoginLogService loginLogService;

    @Autowired
    private ISysOperationLogService operationLogService;

    @SaCheckPermission(value = "system:log_login:list", orRole = "root")
    @GetMapping("loginLoginPageList")
    @Operation(summary = "登录日志分页列表")
    public ApiResponse<Pagination<SysLoginLog>> loginLoginPageList(SysLoginLogReq sysLoginLogReq) {
        Page<SysLoginLog> sysLoginLogPage = loginLogService.pageList(sysLoginLogReq);
        return ApiResponseUtil.success(sysLoginLogPage);
    }

    @SaCheckPermission(value = "system:log_operation:list", orRole = "root")
    @GetMapping("operationLogPageList")
    @Operation(summary = "操作日志分页列表")
    public ApiResponse<Pagination<SysOperationLog>> operationLogPageList(SysOperationLogReq sysOperationLogReq) {
        Page<SysOperationLog> sysOperationLogPage = operationLogService.pageList(sysOperationLogReq);
        return ApiResponseUtil.success(sysOperationLogPage);
    }
}
